package com.wy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wy.dao.CountHistoryDao;
import com.wy.dao.StudentDao;
import com.wy.dao.CourseDao;
import com.wy.dao.TeacherDao;
import com.wy.dao.ApprovalDao;
import com.wy.pojo.CountHistory;

import java.util.Date;
import java.util.List;

@Service
public class CountHistoryService {

    @Autowired
    private CountHistoryDao countHistoryDao;

    @Autowired
    private StudentDao studentDao;

    @Autowired
    private CourseDao courseDao;

    @Autowired
    private TeacherDao teacherDao;

    @Autowired
    private ApprovalDao approvalDao;

    // 用于更新历史记录的方法
    public void updateCountHistory() {

        int studentCount = studentDao.getStudentsCount();
        int courseCount = courseDao.getCoursesCount();
        int teacherCount = teacherDao.getTeachersCount();
        int approvalCount = approvalDao.getApprovalsCount();

        CountHistory history = new CountHistory();
        history.setDate(new Date());
        history.setStudentCount(studentCount);
        history.setOpenCourseCount(courseCount);
        history.setTeacherCount(teacherCount);
        history.setApprovalUntreatedCount(approvalCount);

        countHistoryDao.insertCountHistory(history);
    }

    // 添加获取历史数据的方法
    public List<CountHistory> getCountHistoryByDateRange(String startDate, String endDate) {
        return countHistoryDao.getCountHistoryByDateRange(startDate, endDate);
    }
}
